package com.shu.shiro.common;

public class Result<T> {
    /**
     * code
     */
    private String code;
    /**
     * 消息
     */
    private String msg;
    /**
     * 数据结果
     */
    private T data;

    private Result(T data) {
        this.code=CodeMsg.S00000.getCode();
        this.msg=CodeMsg.S00000.getMsg();
        this.data=data;
    }
    private Result(CodeMsg codeMsg) {
        if (codeMsg==null){
            return ;
        }
        this.code=codeMsg.getCode();
        this.msg=codeMsg.getMsg();
    }

    public Result(String code, String failMsg) {
        this.code=code;
        this.msg=failMsg;
    }

    /**
     * 成功时候调用
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T data){
        return  new Result<T>(data);
    }

    /**
     * 失败时候调用
     * @param codeMsg
     * @param <T>
     * @return
     */
    public static <T> Result<T> error(CodeMsg codeMsg){
        return  new Result<T>(codeMsg);
    }
    public static <T> Result<T> error(String msg){

        return  new Result<T>(CodeMsg.S00001.getCode(),msg);
    }
//    public static <T> Result error(String failMsg){
//        return new Result(CodeMsg.S00001.code,failMsg);
//    }

    public Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
